#include<iostream>
using namespace std;
const int N = 1e3 + 10;
int arr[N];
int ans[N];
int sum;
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (arr[j] > arr[i]) {
				ans[arr[i]]++;
			}
		}
    }
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
		sum += ans[i];
	}
	cout << endl;
	cout<<sum<<endl;
	return 0;
}